﻿using System;
using FlowCanvas;
using FlowCanvas.Nodes;
using LogSystem;
using NodeCanvas.Framework;
using ParadoxNotion;
using ParadoxNotion.Design;
using UnityEngine;

namespace Yoozoo.Gameplay.Liberty.StreetEvent
{
    public class StreetEventCounterEvent : EventNode
    {
        [RequiredField]
        public BBParameter<string> counterName;
        
        private FlowOutput complete;
        
        public override string name
        {
            get
            {
                return string.Format("SCounterEvent:{0} ", counterName.value);
            }
        }

        public override void OnPostGraphStarted()
        {
            StreetTaskCountUtils.OnCounterComplete += OnCounterComplete;
        }

        public override void OnPostGraphStoped()
        {
            StreetTaskCountUtils.OnCounterComplete -= OnCounterComplete;
        }

        private void OnCounterComplete(string cName, int count)
        {
            if (cName == counterName.value.Trim())
            {
                StreetTaskCountUtils.OnCounterComplete -= OnCounterComplete;
                complete.Call(new Flow());
            }
        }

        protected override void RegisterPorts()
        {
            complete = AddFlowOutput("Out");
        }

    }
}